package ModelLayer;
import java.util.ArrayList;

/**
 * Vestbjerg project
 * @GroupB2 (UCN - Computer Science DMAJ0914) 
 */
public class LeaseContainer
{
    // instance variables
    private static LeaseContainer instance;
    private ArrayList<Lease> leaseList;

    /**
     * Constructor for objects of class ProductContainer
     */
    public LeaseContainer()
    {
        leaseList = new ArrayList<Lease>();
    }
    
    public static LeaseContainer getInstance()
    {
        if(instance == null)
        {
            instance = new LeaseContainer();
        }
        return instance;
    }
    
    public void addLease(Lease newLease)
    {
        boolean exist=false;
        for(Lease lease : leaseList)
        {
            if(lease.getId().equals(newLease.getId()))
            {
                exist = true;
            }
        }
        if(!exist)
        {
            leaseList.add(newLease);
        }
    }

    public Lease findLease(String id)
    {
        boolean found = false;
        int i = 0;
        Lease returnLease = null;
        while(i < leaseList.size() && !found)
        {
            if(leaseList.get(i).getId().equals(id))
            {
                found = true;
            }
            else 
            {
                i = i + 1;
            }
        }
        if(found)
        {
            returnLease = leaseList.get(i);
        }
        return returnLease;
    }
    
    public void deleteLease(Lease lease)
    {
        if(leaseList.contains(lease))
        {
            leaseList.remove(lease);
        }
    }
    
    public ArrayList<Lease> getLeaseList() 
    {
     return leaseList;
    }
}
